package cn.com.doone.common.uc.utils;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.ldap.core.AuthenticationSource;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.stereotype.Component;

@Component("propertiesUtils")
public class PropertiesUtils {

	@Value("${wedo.serverPath}")
	private String wedoServerPath;

	@Value("${wedo.secretKey}")
	private String secretKey;

	@Value("${ldap.enable}")
	private boolean ldapEnable;

	@Value("${head.path}")
	private String headPath;

	@Value("${head.docPath}")
	private String headDocPath;

	@Value("${style.path}")
	private String stylePath;

	@Value("${redis.address}")
	private String redisAddress;

	@Value("${redis.port}")
	private int redisPort;

	@Value("${sms.enable}")
	private boolean smsEnable;

	@Value("${sms.url}")
	private String smsUrl;

	@Value("${sms.appKey}")
	private String smsAppKey;

	@Value("${sms.secret}")
	private String smsSecret;
	
	@Value("${sms.clientId}")
	private String smsClientId;
	
	@Value("${check.passwd}")
	private boolean checkPasswd;
	
	@Value("${check.lock}")
	private boolean checkLock;
	
	public boolean isCheckPasswd() {
		return checkPasswd;
	}

	public boolean isCheckLock() {
		return checkLock;
	}

	public String getSmsClientId() {
		return smsClientId;
	}

	public void setSmsClientId(String smsClientId) {
		this.smsClientId = smsClientId;
	}

	public String getRedisAddress() {
		return redisAddress;
	}

	public void setRedisAddress(String redisAddress) {
		this.redisAddress = redisAddress;
	}

	public int getRedisPort() {
		return redisPort;
	}

	public void setRedisPort(int redisPort) {
		this.redisPort = redisPort;
	}

	public String getStylePath() {
		return stylePath;
	}

	public void setStylePath(String stylePath) {
		this.stylePath = stylePath;
	}

	public String getHeadDocPath() {
		return headDocPath;
	}

	public void setHeadDocPath(String headDocPath) {
		this.headDocPath = headDocPath;
	}

	public String getHeadPath() {
		return headPath;
	}

	public void setHeadPath(String headPath) {
		this.headPath = headPath;
	}

	public String getSecretKey() {
		return secretKey;
	}

	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	public String getWedoServerPath() {
		return wedoServerPath;
	}

	public void setWedoServerPath(String wedoServerPath) {
		this.wedoServerPath = wedoServerPath;
	}

	public boolean isLdapEnable() {
		return ldapEnable;
	}

	public void setLdapEnable(boolean ldapEnable) {
		this.ldapEnable = ldapEnable;
	}

	public boolean isSmsEnable() {
		return smsEnable;
	}

	public void setSmsEnable(boolean smsEnable) {
		this.smsEnable = smsEnable;
	}


	@Value("${ldap.url}")
	private String ldapUrl;

	@Value("${ldap.ldapUserDn}")
	private String ldapUserDn;

	@Value("${ldap.ldapUserPwd}")
	private String ldapUserPwd;

	@Value("${ldap.baseDn}")
	private String ldapUaseDn;

	@Bean
	public LdapTemplate ldapTemplate() {
		LdapContextSource ldapContextSource = new LdapContextSource();
		ldapContextSource.setUrl(ldapUrl);
		ldapContextSource.setCacheEnvironmentProperties(false);
		ldapContextSource.setBase(ldapUaseDn);
		ldapContextSource.setAuthenticationSource(new AuthenticationSource() {

			@Override
			public String getCredentials() {
				return ldapUserPwd;
			}

			@Override
			public String getPrincipal() {
				return ldapUserDn;
			}

		});
		return new LdapTemplate(ldapContextSource);
	}
	
	/**
	 * 新入职
	 * @return
	 */
	public Map<String,String> getTheNewSmsMap() {
		Map<String,String> smsMap = new HashMap<String,String>();
		smsMap.put("smsUrl", this.smsUrl);
		smsMap.put("smsAppKey", this.smsAppKey);
		smsMap.put("smsSecret", this.smsSecret);
		smsMap.put("smsTemplateCode", "SMS_14706831");
		return smsMap;
	}
	
	/**
	 * 重置密码模板
	 * @return
	 */
	public Map<String,String> getResetPasswordSmsMap() {
		Map<String,String> smsMap = new HashMap<String,String>();
		smsMap.put("smsUrl", this.smsUrl);
		smsMap.put("smsAppKey", this.smsAppKey);
		smsMap.put("smsSecret", this.smsSecret);
		smsMap.put("smsTemplateCode", "SMS_24605164");
		return smsMap;
	}
	
	/**
	 * 验证码
	 * @return
	 */
	public Map<String,String> getCodeSmsMap() {
		Map<String,String> smsMap = new HashMap<String,String>();
		smsMap.put("smsUrl", this.smsUrl);
		smsMap.put("smsAppKey", this.smsAppKey);
		smsMap.put("smsSecret", this.smsSecret);
		smsMap.put("smsTemplateCode", "SMS_25360300");
		return smsMap;
	}
}
